package com.leap.meeting.dao.imple;

import com.leap.meeting.dao.AdminDAO;
import com.leap.meeting.dao.BaseDAO;
import com.leap.meeting.pojo.Admin;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Component
public class AdminDAOimple extends BaseDAO implements AdminDAO {
    @Override
    public List<Admin> selectAll() {
        try {
            String sql = "SELECT id, name, phone, account, password, email FROM admin";
            return super.executeQuery(Admin.class, sql, null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Admin selectByAccount(String account) {
        try {
            String sql = "SELECT id, name, phone, account, password, email FROM admin where account = ?";
            return super.executeQuerySingle(Admin.class, sql, account);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int update(Admin admin) {
        String sql = "UPDATE admin SET name = ? , phone = ? , account = ? , password = ? , email = ? WHERE id = ?";
        return super.executeUpdate(sql,admin.getName(),admin.getPhone(),admin.getAccount(),admin.getPassword(),admin.getEmail(),admin.getId());
    }
}
